package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.BaseSubject;
import com.ruoyi.base.service.IBaseSubjectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据主题Controller
 * 
 * @author yepanpan
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/base/subject")
public class BaseSubjectController extends BaseController
{
    @Autowired
    private IBaseSubjectService baseSubjectService;

    /**
     * 查询数据主题列表
     */
    @GetMapping("/select")
    public TableDataInfo select(BaseSubject baseSubject)
    {
        PageHelper.startPage(1, 1000, "order_num asc");
        List<BaseSubject> list = baseSubjectService.selectBaseSubjectList(baseSubject);
        return getDataTable(list);
    }

    /**
     * 查询数据主题列表
     */
    @PreAuthorize("@ss.hasPermi('base:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseSubject baseSubject)
    {
        startPage();
        List<BaseSubject> list = baseSubjectService.selectBaseSubjectList(baseSubject);
        return getDataTable(list);
    }

    /**
     * 导出数据主题列表
     */
    @PreAuthorize("@ss.hasPermi('base:subject:export')")
    @Log(title = "数据主题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSubject baseSubject)
    {
        List<BaseSubject> list = baseSubjectService.selectBaseSubjectList(baseSubject);
        ExcelUtil<BaseSubject> util = new ExcelUtil<BaseSubject>(BaseSubject.class);
        util.exportExcel(response, list, "数据主题数据");
    }


    /**
     * 获取数据主题详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:subject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseSubjectService.selectBaseSubjectById(id));
    }

    /**
     * 新增数据主题
     */
    @PreAuthorize("@ss.hasPermi('base:subject:add')")
    @Log(title = "数据主题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BaseSubject baseSubject)
    {
        return toAjax(baseSubjectService.insertBaseSubject(baseSubject));
    }

    /**
     * 修改数据主题
     */
    @PreAuthorize("@ss.hasPermi('base:subject:edit')")
    @Log(title = "数据主题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody BaseSubject baseSubject)
    {
        return toAjax(baseSubjectService.updateBaseSubject(baseSubject));
    }

    /**
     * 删除数据主题
     */
    @PreAuthorize("@ss.hasPermi('base:subject:remove')")
    @Log(title = "数据主题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseSubjectService.deleteBaseSubjectByIds(ids));
    }
}
